/**
 * Created by DuHuiling on 2017/4/24.
 */

var Breadcrumb = require('../../../../src/libs/breadcrumb');

var Result = React.createClass({
    getDefaultProps:function(){
        return{
            data:{},
            url:{
                home:"",
                invest:"",
                account:""
            }
        }
    },
    getInitialState: function () {
        return {
            result:this.props.data.value,
            investSum:0//预期收益
        }
    },
    investSumChangeHandler: function (v) {
        var v = Number(v);
        var val = UMath.Earnings(v,this.state.result.Interest,this.state.result.Duration,PageDM.days.value);
        val = UFormatter.formatMoney(val,2);
        this.setState({
            investSum:val
        });
    },
    componentDidMount:function(){
        var _this = this;
        //console.log(_this.props.data)
        //支付结果
        UEventHub.on(_this.props.data.dmbind + UI_EVENT_CONST.SET_UDM_VALUE_EVENT, function(v){
            //_this.updateResult(v);
            _this.setState({
                result:v
            });
            _this.investSumChangeHandler(v.OrderAmount);//初始预期收益
        });
    },
    render: function () {
        var _url = this.props.url;
        var OrderAmount = UFormatter.formatMoney(this.state.result.OrderAmount,2);
        return (
            <div>
                <Breadcrumb	separator='>' >
                    <Breadcrumb.Item href={_url.home}>首页</Breadcrumb.Item>
                    <Breadcrumb.Item href={_url.invest}>我要投资</Breadcrumb.Item>
                    <Breadcrumb.Item>支付结果</Breadcrumb.Item>
                </Breadcrumb>

                <div className="pay-result">
                    <div className="line"></div>
                    {this.state.result.orderType == -1 ? '' : this.state.result.orderType ?
                        <div className="content">
                            <h1><i className="iconfont icon-success"></i> 订单提交成功，请稍后查看投资记录</h1>
                            <div className="detail">
                                <h2>{this.state.result.ProjectName}</h2>
                                <ul className="clearfix">
                                    <li className="">投标金额</li>
                                    <li>预期收益</li>
                                    <li>还款时间</li>
                                    <li>{OrderAmount + "元"}</li>
                                    <li><span className="fc-main"><strong>{this.state.investSum}</strong></span> 元</li>
                                    <li>{this.state.result.RepayBegin}</li>
                                </ul>
                            </div>
                            <div className="button">
                                您现在可以<a href={_url.account} className="btn btn-confirm">进入账户中心</a><a href={_url.home} className="btn btn-cancel">返回首页</a>
                            </div>
                            <div className="fc-light tips">如需查看更多投标信息，请进入您的账户中心查看！</div>
                        </div> :
                        <div className="content">
                            <h1 className="fc-main"><i className="iconfont icon-failure"></i> 抱歉，订单支付不成功</h1>
                            <div className="tips-failure">{this.state.result.ErrorTips}</div>
                            <div className="button"><a href="javascript:;" onClick={this.state.result.retry} className="btn btn-cancel">返回重试</a></div>
                        </div>
                    }
                </div>
            </div>
        )
    }
});
module.exports = Result;